package com.wudl.govern.controller;

import com.wudl.common.api.CommonResult;
import com.wudl.govern.domain.DbSource;
import com.wudl.govern.service.MetaStatisticsService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ：wudl
 * @date ：Created in 2022-04-05 0:20
 * @description：元数据统计
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("/metastatistics")
public class MetaStatisticsController {
    @Autowired
    MetaStatisticsService metaStatisticsService;
    /**下拉框*/
    @ApiOperation(value="元数据统计下拉框", notes="元数据统计下拉框" ,httpMethod="POST")
    @PostMapping("/select-library-drop")
    public CommonResult<List> selectRetrievalLibrary(@RequestBody Map map) {

        List<Object> objects = metaStatisticsService.selectRetrievalLibraryList(map);
        return CommonResult.success(objects);
    }

    /**饼状图
     *
     * {
     *     "dbSourceId":130
     * }
     * */
    @ApiOperation(value="元数据统计饼状图", notes="元数据统计饼状图" ,httpMethod="POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name="dbSourceId", value="数据库主键id")
    })
    @PostMapping("/select-retrieval-cake")
    public CommonResult selectRetrievalCake(@RequestBody Map map) {
//        return metaStatisticsService.statisticsCake(map);
        List<Object> objects = metaStatisticsService.selectRetrievalCake(map);
        return CommonResult.success(objects);
    }

    /**柱状图
     * "pageNumber":1,
     * "pageSize":10
     * */
    @ApiOperation(value="元数据统计柱状图", notes="元数据统计柱状图" ,httpMethod="POST")
    @PostMapping("/select-retrieval-column")
    public Object selectRetrievalColumn(@RequestBody Map map) {

//        return metaStatisticsService.statisticsColumn(map);
        List<Object> objects = metaStatisticsService.selectRetrievalColumn(map);
        return CommonResult.success(objects);
    }

    /**’柱形数据库名称‘查询功能
     *
     * "pageNumber":1,
     * "pageSize":10
     * */
    @ApiOperation(value="柱形数据库名称", notes="柱形数据库名称" ,httpMethod="POST")
    @PostMapping("/select-retrieval-dbname")
    public CommonResult<List<DbSource>> statisticsDbname(@RequestBody Map map) {
//        UserInfo userInfo = dataDictUtils.getUserInfo();
//        if(userInfo == null){
//            return com.isky.govern.util.response.ResultUtil.fail(MetaBaseConstant.META_BASE_LOGIN);
//        }
//        map.put("deptId",userInfo.getDeptId());
//        map.put("deptId",1);
//        return metaStatisticsService.statisticsDbname(map,session);
        List<DbSource> dbSources = metaStatisticsService.selectRetrievalLibrary(map);
        return CommonResult.success(dbSources);
    }

}
